package com.zx.centers.dataservice.mybatis.mapper.timing;

import com.zx.centers.dataservice.mybatis.domain.timing.TimingTask;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;

public interface TimingTaskMapper {
    @Delete({
        "delete from timing_task",
        "where id = #{id,jdbcType=BIGINT}"
    })
    int deleteByPrimaryKey(Long id);

    @Insert({
        "insert into timing_task (id, task_code, ",
        "task_name, task_type, ",
        "task_url, task_param, ",
        "task_class, remark, ",
        "create_time, update_time, ",
        "task_cron, task_status, ",
        "task_retry)",
        "values (#{id,jdbcType=BIGINT}, #{taskCode,jdbcType=VARCHAR}, ",
        "#{taskName,jdbcType=VARCHAR}, #{taskType,jdbcType=VARCHAR}, ",
        "#{taskUrl,jdbcType=VARCHAR}, #{taskParam,jdbcType=VARCHAR}, ",
        "#{taskClass,jdbcType=VARCHAR}, #{remark,jdbcType=VARCHAR}, ",
        "#{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP}, ",
        "#{taskCron,jdbcType=VARCHAR}, #{taskStatus,jdbcType=BIT}, ",
        "#{taskRetry,jdbcType=INTEGER})"
    })
    int insert(TimingTask record);

    @InsertProvider(type=TimingTaskSqlProvider.class, method="insertSelective")
    int insertSelective(TimingTask record);

    @Select({
        "select",
        "id, task_code, task_name, task_type, task_url, task_param, task_class, remark, ",
        "create_time, update_time, task_cron, task_status, task_retry",
        "from timing_task",
        "where id = #{id,jdbcType=BIGINT}"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true),
        @Result(column="task_code", property="taskCode", jdbcType=JdbcType.VARCHAR),
        @Result(column="task_name", property="taskName", jdbcType=JdbcType.VARCHAR),
        @Result(column="task_type", property="taskType", jdbcType=JdbcType.VARCHAR),
        @Result(column="task_url", property="taskUrl", jdbcType=JdbcType.VARCHAR),
        @Result(column="task_param", property="taskParam", jdbcType=JdbcType.VARCHAR),
        @Result(column="task_class", property="taskClass", jdbcType=JdbcType.VARCHAR),
        @Result(column="remark", property="remark", jdbcType=JdbcType.VARCHAR),
        @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="update_time", property="updateTime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="task_cron", property="taskCron", jdbcType=JdbcType.VARCHAR),
        @Result(column="task_status", property="taskStatus", jdbcType=JdbcType.BIT),
        @Result(column="task_retry", property="taskRetry", jdbcType=JdbcType.INTEGER)
    })
    TimingTask selectByPrimaryKey(Long id);

    @UpdateProvider(type=TimingTaskSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(TimingTask record);

    @Update({
        "update timing_task",
        "set task_code = #{taskCode,jdbcType=VARCHAR},",
          "task_name = #{taskName,jdbcType=VARCHAR},",
          "task_type = #{taskType,jdbcType=VARCHAR},",
          "task_url = #{taskUrl,jdbcType=VARCHAR},",
          "task_param = #{taskParam,jdbcType=VARCHAR},",
          "task_class = #{taskClass,jdbcType=VARCHAR},",
          "remark = #{remark,jdbcType=VARCHAR},",
          "create_time = #{createTime,jdbcType=TIMESTAMP},",
          "update_time = #{updateTime,jdbcType=TIMESTAMP},",
          "task_cron = #{taskCron,jdbcType=VARCHAR},",
          "task_status = #{taskStatus,jdbcType=BIT},",
          "task_retry = #{taskRetry,jdbcType=INTEGER}",
        "where id = #{id,jdbcType=BIGINT}"
    })
    int updateByPrimaryKey(TimingTask record);
}